<script language="javascript">
    $(document).ready(function(){
        $("#checkall").click(function(){
            var checked_status = this.checked;
            $('input[type="checkbox"]').each(function(){
               this.checked = checked_status;
            });
        });
    });
</script>
<script language="javascript">
    $(document).ready(function(){
        $("#checkall").click(function(){
            var checked_status = this.checked;
            $('input[type="checkbox"]').each(function(){
               this.checked = checked_status;
            });
        });
    });
</script>
<?php echo $this->Form->create('KhachHang',array('action'=>'admin_process')); ?>
<h1 align="center">DANH MỤC KHÁCH HÀNG</h1>

<table>
    <thead>
    <tr>
		<th><?php echo $this->Form->checkbox('all',array('id'=>'checkall')); ?></th>
        <th><?php echo $this->Paginator->sort('ID', 'ID'); ?></th>
        <th><?php echo $this->Paginator->sort('DOITUONGKH_ID', 'MÃ ĐỐI TƯỢNG'); ?></th>
        <th><?php echo $this->Paginator->sort('TENKH', 'TÊN KHÁCH HÀNG'); ?></th>
        <th><?php echo $this->Paginator->sort('DIACHIKH', 'ĐỊA CHỈ KHÁCH HÀNG'); ?></th>
        <th>THAY ĐỔI</th>
    </tr>
    </thead>

    <?php foreach ($khachhangs as $khachhang): ?>
    <tr>
		<td><?php echo $this->Form->checkbox('KhachHang.id.'.$khachhang['KhachHang']['id']); ?></td>
        <td><?php echo $khachhang['KhachHang']['id']; ?></td>
        <td><?php echo $khachhang['KhachHang']['DOITUONGKH_ID']; ?></td>
        <td><?php echo $khachhang['KhachHang']['TENKH']; ?></td>
        <td><?php echo $khachhang['KhachHang']['DIACHIKH']; ?></td>
        <td><?php  if ($this->Session->read('quyen') != 'nhanvien') {
            echo $this->Html->link($this->Html->image('/images/user_edit.png'), array('action' => 'edit', $khachhang['KhachHang']['id']),array('escape' => false));
        } else echo '&nbsp';?>
            <?php if ($this->Session->read('quyen') == 'quantri') {
                echo $this->Html->link($this->Html->image('/images/trash.png'), array('action' => 'delete', $khachhang['KhachHang']['id']),
                    array('confirm' => 'Bạn có chắc chắn muốn xóa?', 'escape' => false));
            } ?>
        </td>
    </tr>
    <?php endforeach; ?>
</table>

<?php
     echo $this->Form->end('Xóa các mục đã chọn', array('action' => 'Delete'));
?>

<div id="pagination">
    <div class="paging">
        <?php echo $this->Paginator->first('Trang đầu'); ?>
        <?php echo $this->Paginator->prev('<<' . __('Lùi', true),
        array(), null, array('class' => 'disabled')); ?>
        <?php echo $this->Paginator->numbers(); ?>
        <?php echo $this->Paginator->next(__('Tới', true) . '>>',
        array(), null, array('class' => 'disabled')); ?>
        <?php echo $this->Paginator->last('Trang cuối'); ?>
    </div>
</div>

<?php
    echo $this->Html->link('Thêm khách hàng', array('controller' => 'khach_hangs', 'action' => 'add'), array('class' => 'add'));
?>

<div class="clear"></div>

